<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("utf-8");%>
<%@ include file="pub/top_list2.jsp"%>   
<%
String names = (String) request.getSession().getAttribute("name");
if(request.getParameter("username")!=null&&request.getParameter("username")!=""){
	String sql = "insert into manageadd(userid,username,telephone,province,city,distric,address,state) values(?,?,?,?,?,?,?,?)";
	Object[] param=new Object[8];	
	param[0] =names;
	param[1] =request.getParameter("username"); 
	param[2] =request.getParameter("tele");
	param[3] =request.getParameter("province2");
	param[4] =request.getParameter("city2");
	param[5] =request.getParameter("county2");
	param[6] =request.getParameter("address");
	param[7] =request.getParameter("state2");	
	db.executeUpdate(sql, param);
}
%>
<script type="text/javascript" src="<%=basePath%>js/city.js"></script>
<script>
function fun1(){
	var province2= $("#province").find("option:selected").text();
	var city2= $("#city").find("option:selected").text();
	var county2= $("#county").find("option:selected").text();
	document.getElementById("province2").value=province2;
	document.getElementById("city2").value=city2;
	document.getElementById("county2").value=county2;
	//console.log($("#province2").val());
}
function fun2(){
	var userid='<%=names%>'
	if($(".checkboxa label").hasClass('checkd')){
		document.getElementById("state2").value=1;
		$.ajax({
			type:"post",
			url:"stateAjax.jsp",
			dataType:"text",
			async : false,
			cache : false,
			data:"userid="+userid,
			success:function(){
				alert("您已将当前地址设置为默认地址")
			},
			error:function(e){
				console.log(e)
			}
		});
	}else{
		document.getElementById("state2").value=0;
	}
}

</script>


<body>
	<header class="top-header fixed-header">
		<a class="icona" href="addres.jsp">
				<img src="images/left.png"/>
			</a>
		<h3>添加地址</h3>			
			<a class="text-top" >
			</a>
	</header>
	
	<div class="contaniner fixed-conta">
		<form action="go-address.jsp" method="post" class="change-address" id="save">
			<ul>
				<li>
					<label class="addd">收货人：</label>
					<input type="text" name="username" value="" required="required"/>
				</li>
				<li>
					<label class="addd">手机号：</label>
					<input type="tel" name="tele" value="" required="required"/>
				</li>
				<li>
					<label class="addd">所在地区：</label>
					<select id="province" style="width:74px" name="province" onchange="doProvAndCityRelation();">
  　　　　　　　			　	<option id="choosePro" style="width:74px"  value="北京市">选择省份</option>
  　　　　　			</select>
  					<select id="city" style="width:74px" name="city" onchange="doCityAndCountyRelation();">
 　　　　　				　　　<option id='chooseCity' style="width:74px" value='北京市'>选择城市</option>
 　　　　			　　</select>
 				   <select id="county" style="width:74px" name="county" onchange="fun1()">
 　　　　　　　				　<option id='chooseCounty' style="width:74px" value='朝阳区'>选择区/县</option>
　　　　　　		   </select>
					<input type="text" name="province2" id="province2" value=""  style="display:none"/>
					<input type="text" name="city2" id="city2" value=""  style="display:none"/>
					<input type="text" name="county2" id="county2" value=""  style="display:none"/>
				</li>
				<li>
					<label class="addd">详细地址：</label>
					<textarea name="address" required="required"></textarea>
				</li>
			</ul>
			
			<ul>
				<li class="checkboxa">
					<!-- <input type="checkbox" name="state" id="state" value="0" onclick="fun2()" style="">设置为默认地址<br> -->
					<input type="text" name="state2" id="state2" value="0"  style="display:none"/>
					<input type="checkbox"  id="state" name="state" onclick="fun2()"/>
					<label class="check" for="state" onselectstart="return false"  >设置为默认地址</label>
				</li>
			</ul>
			<!-- <ul>
				<li>
					<h3>删除此地址</h3>
				</li>
			</ul> -->
			<input type="submit" value="保存" />
		</form>
	</div>
	
	<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(".checkboxa label").on('touchstart',function(){
			if($(this).hasClass('checkd')){
				$(".checkboxa label").removeClass("checkd");
			}else{
				$(".checkboxa label").addClass("checkd");
			}
		})
	</script>
	

</body>
</html>